import path from 'path';
const config = {
  projectName: 'fine-cinema-taro',
  date: '2024-4-17',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: `dist/${process.env.TARO_ENV}`, 
  plugins: [],
  alias: {
    '@/components': path.resolve(__dirname, '..', 'src/components'),
    '@/utils': path.resolve(__dirname, '..', 'src/utils'),
    '@/src': path.resolve(__dirname, '..', 'src'),
    '@/static': path.resolve(__dirname, '..', 'src/static'),
    '@/config': path.resolve(__dirname, '..', 'src/config'),
    '@/images': path.resolve(__dirname, '..', 'src/images'),
    '@/pages': path.resolve(__dirname, '..', 'src/pages'),
    '@/services': path.resolve(__dirname, '..', 'src/services'),
    '@/libs': path.resolve(__dirname, '..', 'src/libs'),
    '@/giftCardSubPack': path.resolve(__dirname, '..', 'src/giftCardSubPack'),
    '@/mainSubPack': path.resolve(__dirname, '..', 'src/mainSubPack'),
    '@/orderSubPack': path.resolve(__dirname, '..', 'src/orderSubPack'),
    '@/dataTransfer': path.resolve(__dirname, '..', 'src/dataTransfer'),
  },
  defineConstants: {
  },
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  framework: 'react',
  compiler: {
    type: 'webpack5',
    prebundle: {
      enable:false
    },
  },
  cache: {
    enable: false
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {

        }
      },
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    },
    miniCssExtractPluginOption: {
      ignoreOrder: true,
    }
  },
  h5: {
    publicPath: '/e',
    staticDirectory: 'static',
    output: {
      environment: {
        asyncFunction: true,
      }
    },
    postcss: {
      autoprefixer: {
        enable: true,
        config: {
        }
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    },
    devServer: {
      hot: false,
      proxy: {
        '/api': {
          target: 'https://sit.api.tuan.ant.shop',
          pathRewrite: {
            '^/api/': '/'
          },
          changeOrigin: true
        }
      }
    }
  },
  output: {
    filename: 'js/[name].[hash:8].js',
    chunkFilename: 'js/[name].[chunkhash:8].js',
  },
  miniCssExtractPluginOption: {
    filename: 'css/[name].[hash:8].css',
    chunkFilename: 'css/[name].[chunkhash:8].css',
  },
  webpackChain(chain) {
    chain.module.rule('image').exclude.add(path.resolve(__dirname, '../src/images/icons/')).end();

    chain.merge({
      module: {
        rule: {
          svgloader: {
            test: /\.svg$/,
            include: [path.resolve(__dirname, '../src/images/icons')],
            use: [
              {
                loader: 'svg-sprite-loader',
                options: {},
              },
              {
                loader: 'svgo-loader',
                options: {
                  plugins: [
                    {
                      name: 'convertColors',
                      params: {
                        currentColor: true,
                      },
                    },
                  ],
                },
              },
            ],
          },
        },
      },
    });
  },
  imageUrlLoaderOption: {
    limit: 5000,
    exclude: [path.resolve(__dirname, '../src/images/icons')],
    name: 'static/images/[name].[hash:8].[ext]',
  },
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}
